﻿@model Nop.Admin.Models.Customers.CustomerAddressModel

@if (Model.Address.CountryEnabled && Model.Address.StateProvinceEnabled)
{
    <script type="text/javascript">
        $(function() {
            $("#@Html.FieldIdFor(model => model.Address.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.Address.StateProvinceId)");
                $.ajax({
                    cache: false,
                    type: "GET",
                    url: "@(Url.Action("GetStatesByCountryId", "Country"))",
                    data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
                    success: function(data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert('Failed to retrieve states.');
                    }
                });
            });
        });
    </script>
}
@Html.HiddenFor(model => model.Address.Id)
@Html.HiddenFor(model => model.Address.FirstNameEnabled)
@Html.HiddenFor(model => model.Address.FirstNameRequired)
@Html.HiddenFor(model => model.Address.LastNameEnabled)
@Html.HiddenFor(model => model.Address.LastNameRequired)
@Html.HiddenFor(model => model.Address.EmailEnabled)
@Html.HiddenFor(model => model.Address.EmailRequired)
@Html.HiddenFor(model => model.Address.CompanyEnabled)
@Html.HiddenFor(model => model.Address.CompanyRequired)
@Html.HiddenFor(model => model.Address.CountryEnabled)
@Html.HiddenFor(model => model.Address.StateProvinceEnabled)
@Html.HiddenFor(model => model.Address.CityEnabled)
@Html.HiddenFor(model => model.Address.CityRequired)
@Html.HiddenFor(model => model.Address.StreetAddressEnabled)
@Html.HiddenFor(model => model.Address.StreetAddressRequired)
@Html.HiddenFor(model => model.Address.StreetAddress2Enabled)
@Html.HiddenFor(model => model.Address.StreetAddress2Required)
@Html.HiddenFor(model => model.Address.ZipPostalCodeEnabled)
@Html.HiddenFor(model => model.Address.ZipPostalCodeRequired)
@Html.HiddenFor(model => model.Address.CellPhoneEnabled)
@Html.HiddenFor(model => model.Address.CellPhoneRequired)
@Html.HiddenFor(model => model.Address.PhoneEnabled)
@Html.HiddenFor(model => model.Address.PhoneRequired)
@Html.HiddenFor(model => model.Address.FaxEnabled)
@Html.HiddenFor(model => model.Address.FaxRequired)
<table>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.Address.Id):
        </td>
        <td class="adminData">
            @Html.DisplayFor(model => model.Address.Id)
        </td>
    </tr>
    @if (Model.Address.FirstNameEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.FirstName):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.FirstName)
                @Html.ValidationMessageFor(model => model.Address.FirstName)
            </td>
        </tr>
    }
    @if (Model.Address.LastNameEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.LastName):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.LastName)
                @Html.ValidationMessageFor(model => model.Address.LastName)
            </td>
        </tr>
    }
    @if (Model.Address.EmailEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.Email):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.Email)
                @Html.ValidationMessageFor(model => model.Address.Email)
            </td>
        </tr>
    }
    @if (Model.Address.CompanyEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.Company):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.Company)
                @Html.ValidationMessageFor(model => model.Address.Company)
            </td>
        </tr>
    }
    @if (Model.Address.CountryEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.CountryId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.Address.CountryId, Model.Address.AvailableCountries)
                @Html.ValidationMessageFor(model => model.Address.CountryId)
            </td>
        </tr>
    }
    @if (Model.Address.CountryEnabled && Model.Address.StateProvinceEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.StateProvinceId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.Address.StateProvinceId, Model.Address.AvailableStates)
                @Html.ValidationMessageFor(model => model.Address.StateProvinceId)
            </td>
        </tr>
    }
    @if (Model.Address.CityEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.City):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.City)
                @Html.ValidationMessageFor(model => model.Address.City)
            </td>
        </tr>
    }
    @if (Model.Address.StreetAddressEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.Address1):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.Address1)
                @Html.ValidationMessageFor(model => model.Address.Address1)
            </td>
        </tr>
    }
    @if (Model.Address.StreetAddress2Enabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.Address2):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.Address2)
                @Html.ValidationMessageFor(model => model.Address.Address2)
            </td>
        </tr>
    }
    @if (Model.Address.ZipPostalCodeEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.ZipPostalCode):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.ZipPostalCode)
                @Html.ValidationMessageFor(model => model.Address.ZipPostalCode)
            </td>
        </tr>
    }
    @if (Model.Address.CellPhoneEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.CellPhoneNumber):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.CellPhoneNumber)
                @Html.ValidationMessageFor(model => model.Address.CellPhoneNumber)
            </td>
        </tr>
    }
    @if (Model.Address.PhoneEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.PhoneNumber):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.PhoneNumber)
                @Html.ValidationMessageFor(model => model.Address.PhoneNumber)
            </td>
        </tr>
    }
    @if (Model.Address.FaxEnabled)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Address.FaxNumber):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Address.FaxNumber)
                @Html.ValidationMessageFor(model => model.Address.FaxNumber)
            </td>
        </tr>
    }
</table>
